<?php
namespace Home\Controller;
use Think\Controller;
/**
* ShowController
*/
class ShowController extends Controller
{
	public function index(){
		$id = I('get.id');
		$pathname = I('get.pathname');
		$search="/".MODULE_NAME."/search/index";
		$template = M('category')->where("pathname='$pathname'")->getfield('show_template');
		$com = M("configs")->where("name='CFG_WEBNAME'")->getField("value");
		$modelid = M('category')->where("pathname='$pathname'")->getfield('modelid');
		$table= M('model')->where("modelid='$modelid'")->getfield('table');
		$tablename="model_".$table; 
		$title = M("$tablename")->where("id=$id")->getfield('title');
		$this->assign("com",$com);
		$this->assign("title",$title);
		$this->assign("search",$search);
		$template = str_replace('.html', '', $template);
		$this->display('/'.$template);
    }
    public function show(){
		$id = I('get.id');
		$search="/".MODULE_NAME."/search/index";
		$template = M('category')->where("id={$id}")->getfield('show_template');
		$com=M("configs")->where("name='CFG_WEBNAME'")->getField("value");
		$modelid = M('category')->where("pathname='$pathname'")->getfield('modelid');
		$table= M('model')->where("modelid='$modelid'")->getfield('table');
		$tablename="model_".$table; 
		$title = M("$tablename")->where("id=$id")->getfield('title');
		$info = M('category')->where("id={$id}")->find();
		$template = str_replace('.html', '', $template);
		$this->assign("com",$com);
		$this->assign("search",$search);
		$this->assign("title",$title);
		$this->display('/'.$template);
    }

    // ajax设置点击量
	public function set_hits(){
	  $id=$_GET['id'];
	  $pname="{$_GET['pname']}";
	  $data['hits']=1;
	  $modelid=M('category')->where("pathname='".$pname."'")->getField("modelid");
	  $tablename=M("model")->where("modelid=$modelid")->getField("table");
	  if(!$id){
	  	return;
	  }
	  M("model_{$tablename}")->where("id = $id")->setInc('hits');
	}
}